//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		account:app.setting.account,
		pagetitle:'申请退款' + '-' + app.setting.title,
		
	},
	onReady: function (){
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var page=this;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			console.log('refund');console.log(pagedata);			
			page.setData({
				pagedata:pagedata
			});
			if(app.access.op=='list'){
				setTimeout(()=>{page.getlist(1);},500);
			}
		});
	},
	getlist:function(e){
		var the=this
		var data={}
		var page=the.data.page
		var pagedata=the.data.pagedata
		var isnodata = the.data.isnodata
		pagedata.list=pagedata.list?pagedata.list:[]
		if(e){
			if(e.currentTarget){
				data = e.currentTarget.dataset;
				pagedata.params.status=data.status
			}
			pagedata.list=[]
			page=1
			isnodata=false;
		}else{
			if(isnodata){
				return false;
			}
		}
		var userdeleted=data.userdeleted?data.userdeleted:'';
		app.util.get('/order.refund/getlist/status='+pagedata.params.status+'&page='+page,function(res){
			if(res=='none'){
				the.setData({
					isnodata:true,
					'pagedata.list':pagedata.list,
					'pagedata.params.status':pagedata.params.status,
					'pagedata.userdeleted':userdeleted,
					loading:false,
				});
			}else{
				pagedata.list = pagedata.list.concat(res)
				page++
				the.setData({
					'pagedata.list':pagedata.list,
					'pagedata.params.status':pagedata.params.status,
					'pagedata.userdeleted':userdeleted,
					page:page,
					isnodata:isnodata,
					loading:false,
				});
			}
		});
	},
	//翻页
	onReachBottom: function () {
		var isnodata=this.data.isnodata
		var loading=this.data.loading
		if(!isnodata && !loading){
			this.getlist()
		}
	},
	chooseImage:function(e){
		var that =this
		wx.chooseImage({
		  count: 5, // 默认9
		  sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
		  sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
		  success: function (res) {
			// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
			var tempFilePaths = res.tempFilePaths
			 that.setData({
					'pagedata.item.images': tempFilePaths,
			  })
		  }
		})
	},
	setcontent:function(e){
		var that =this
		that.setData({
			'pagedata.item.content': e.detail.value,
	    })
	},
	setprice:function(e){
		var that =this
		that.setData({
			'pagedata.item.price': e.detail.value,
	    })
	},
	setsn:function(e){
		var that =this
		that.setData({
			'pagedata.item.sn': e.detail.value,
	    })
	},
	applypost:function(){
		var that =this
		var data={};
		var pagedata=that.data.pagedata
		app.util.post('jy_weishop/order.refund/apply/',pagedata.item);
	},
	sendpost:function(){
		var that =this
		var data={};
		var pagedata=that.data.pagedata
		app.util.post('jy_weishop/order.refund/send/',pagedata.item);
	},
	expressChange: function(e) {
		//console.log('picker发送选择改变，携带值为', e.detail.value)
		var that =this
		var pagedata=that.data.pagedata
		that.setData({
			'pagedata.item.com': pagedata.express_types[e.detail.value].name,
	    })
	  },
	cancel:function(e){
		var data=e.currentTarget.dataset;
		app.util.post('jy_weishop/order.refund/cancel/',data);
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	formSubmit:function(event){
		var data=event.detail.value;
		app.util.post('jy_weishop/order.refund/post/',data);
	}
});